using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;

namespace _18miljard.Config
{
	public class ConnectionParameters
	{
		string connectionString;
		string providerName;

		internal ConnectionParameters(string connectionString, string providerName)
		{
			this.connectionString = connectionString;
			this.providerName = providerName;
		}

		public string ConnectionString
		{
			get { return this.connectionString; }
		}

		public string ProviderName
		{
			get { return this.providerName; }
		}

		public string PhysicalDbPath
		{
			get
			{
				Regex regEx = new Regex("\\|DataDirectory\\|(?'dbfile'.*\\.accdb)", RegexOptions.Compiled | RegexOptions.IgnoreCase);

				Match match = regEx.Match(this.connectionString);

				Group dbFile = match.Groups["dbfile"];

				return System.Web.Hosting.HostingEnvironment.MapPath("/App_Data/") + dbFile.Value.Trim();
			}
		}

		public string ConnectionStringWithPhysicalDbPath
		{
			get
			{
				return this.connectionString.Replace("|DataDirectory|", System.Web.Hosting.HostingEnvironment.MapPath("/App_Data/"));
			}
		}

	}
}
